<template>
	<view class="wrap">

		<view class="top">
			<u-icon name="order" class="logo"></u-icon>Kant Boot软件需求平台
		</view>
		<view class="content">

			<view class="title">欢迎登录Kant Boot</view>

			<u-field class="u-border-bottom" v-model="user.username" icon="account-fill" placeholder="请输入账号或手机号">
			</u-field>

			<view style="height: 50rpx;"></view>

			<u-field class="u-border-bottom" v-model="user.password" type="password" :icon="passwordIcon"
				@focus="passwordFocus()" @blur="passwordBlur()" placeholder="请输入密码">
			</u-field>


			<view class="tips" style="height: 40rpx;"></view>
			<u-button v-if="user.username==null||user.username.length<1||user.password==null||user.password.length<6"
				style="opacity: .5;" :ripple="true" ripple-bg-color="#F0F0F0" class="getCaptcha">登录</u-button>

			<u-button v-else @click="login" :ripple="true" ripple-bg-color="#F0F0F0" class="getCaptcha">登录</u-button>

			<view class="alternative">
				<view class="password"></view>
			</view>
		</view>

		<view class="buttom" style="position: fixed;bottom: 0;">
			<view class="loginType">
				<view class="wechat item">
					<u-divider>其它登录</u-divider>
					<view style="height: 30rpx;"></view>
					<view class="icon">
						<u-icon @click="showCloseWecht()" size="100" name="weixin-fill" color="rgb(83,194,64)"></u-icon>
					</view>
				</view>
			</view>

		</view>

		<u-button @click="toJoin()" size="mini" :ripple="true" style="position: fixed;bottom: 20rpx;right: 20rpx;"
			ripple-bg-color="#F0F0F0" type="warning">前往注册</u-button>

		<u-toast ref="uToast"></u-toast>
	</view>

	</view>
</template>

<script>
	import Request from '../../utils/Request.js'
	import Util from '../../utils/Util.js'

	let that;
	export default {
		data() {
			return {
				passwordIcon: "lock-fill",
				user: {
					username: "",
					password: ""
				}
			}
		},
		mounted() {
			that = this;
			this.getUserInfo();
		},
		computed: {},
		methods: {
			showCloseWecht() {
				that.$refs.uToast.show({
					title: "微信登录暂时关闭",
					type: 'warning',
					duration: '2300'
				});
			},
			//获取用户信息
			getUserInfo() {
				Util.request({
					url: Request.path+"ces-user/get_user_info",
					success(res) {
						that.userInfo = res.data.data;
						if(that.userInfo!=null){
							uni.reLaunch({
								url: '/pages/index/index'
							});
						}
					}
				});
			},
			passwordFocus() {
				this.passwordIcon = "lock-opened-fill";
			},
			passwordBlur() {
				this.passwordIcon = "lock-fill";
			},
			login() {
				Util.requestInNotLoginPage({
					url: Request.path + "ces-user/login",
					data: that.user,
					success(res) {
						if (res.data.state == 2000) {

							uni.reLaunch({
								url: '/pages/index/index'
							})

							that.$refs.uToast.show({
								title: res.data.msg,
								type: 'success',
								duration: '2300'
							});
							return;
						}
						that.$refs.uToast.show({
							title: res.data.errMsg,
							type: 'error',
							duration: '2300'
						});
					}
				});
			},
			toJoin() {
				uni.navigateTo({
					url: "../join/join"
				})
			}
		}
	};
</script>

<style lang="scss" scoped>
	.top {
		padding: 30rpx;
		color: $fyf-font-color;
		font-weight: bold;

		.logo {
			font-size: 35rpx;
			color: #FFFFFF;
			background: $fyf-button-background;
			padding: 10rpx;
			border-radius: 55%;
			margin-right: 10rpx;
		}
	}

	.wrap {
		font-size: 28rpx;

		.content {
			width: 600rpx;
			margin: 80rpx auto 0;
			text-align: left;

			.title {
				text-align: left;
				font-size: 45rpx;
				font-weight: 500;
				margin-bottom: 0rpx;
			}

			.u-border-bottom {
				border-bottom: 1rpx solid gray;
			}

			input {
				text-align: left;

				margin-bottom: 10rpx;
				padding-bottom: 6rpx;
			}

			.tips {
				color: $u-type-info;
				margin-bottom: 60rpx;
				margin-top: 8rpx;
			}

			.issue {
				color: $fyf-font-color;
			}

			.getCaptcha {
				background: $fyf-button-background;
				color: $fyf-button-color;
				border: none;
				width: 60%;
				font-size: 30rpx;
				padding: 12rpx 0;

				&::after {
					border: none;
				}
			}

			.getCaptcha::active {
				color: $fyf-button-color;
			}

			.alternative {
				color: $u-tips-color;
				display: flex;
				justify-content: space-between;
				margin-top: 30rpx;
			}
		}

		.buttom {
			position: relative;
			bottom: 0;

			.loginType {
				display: flex;
				padding: 100rpx 150rpx 150rpx 150rpx;
				justify-content: space-between;

				.item {
					display: flex;
					flex-direction: column;
					align-items: center;
					color: $u-content-color;
					font-size: 28rpx;
				}
			}

			.hint {
				padding: 20rpx 40rpx;
				font-size: 20rpx;
				color: $u-tips-color;

				.link {
					color: $u-type-warning;
				}
			}
		}
	}
</style>
